package io.renren.modules.app.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.Query;
import io.renren.modules.app.dao.user.UserIntentionJobDao;
import io.renren.modules.app.entity.company.YcCompanyFind;
import io.renren.modules.app.entity.company.YcUserFind;
import io.renren.modules.app.entity.index.YcRecommend;
import io.renren.modules.app.entity.user.UserIntentionJobEntity;
import io.renren.modules.app.service.user.UserIntentionJobService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import io.renren.common.utils.PageUtils;



@Service("UserIntentionJobService")
public class UserIntentionJobServiceImpl extends ServiceImpl<UserIntentionJobDao, UserIntentionJobEntity> implements UserIntentionJobService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserIntentionJobEntity> page = this.page(
                new Query<UserIntentionJobEntity>().getPage(params),
                new QueryWrapper<UserIntentionJobEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<UserIntentionJobEntity> queryByUserId(Integer userId) {

        return baseMapper.queryByUserId(userId);
    }

    @Override
    public UserIntentionJobEntity getInfoById(Integer id) {
        return baseMapper.selectInfoById(id);
    }

    /**
     * 查询公司发现页数据
     */
    public List<YcCompanyFind> selectCompanyFindList(String titles, String area, String trade,
                                                     String scale, String age, String cityId,
                                                     Integer page, Integer limit) {
        if (StringUtils.isNotEmpty(cityId) && cityId.length() >5) {
            cityId = cityId.substring(0, 4);
        }
        return baseMapper.selectCompanyFindList(titles, area, trade, scale, age, cityId, page, limit);
    }


    /**
     * 查询用户发现页数据
     */
    public List<YcUserFind> selectUserFindList(String titles, String area, String trade, String scale,
                                               String age, String cityId, Integer page, Integer limit) {
        if (StringUtils.isNotEmpty(cityId) && cityId.length() > 5) {
            cityId = cityId.substring(0,4);
        }
        return baseMapper.selectUserFindList(titles, area, trade, scale, age, cityId, page, limit);
    }

    public boolean updateCompanyMemberPoints(String companyId) {
        return baseMapper.updateCompanyMemberPoints(companyId) > 0;
    }

    public List<YcRecommend> getRecommendList(String area, String companyName, Integer page, Integer limit) {
        if (StringUtils.isNotEmpty(area) && area.length() > 5) {
            area = area.substring(0, 4);
        }
        return baseMapper.getRecommendList(area, companyName, page, limit);
    }
}